/*     */ package com.cr.common.utils;
/*     */ 
/*     */ import com.cr.common.core.text.Convert;
/*     */ import java.io.IOException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import org.springframework.web.context.request.RequestAttributes;
/*     */ import org.springframework.web.context.request.RequestContextHolder;
/*     */ import org.springframework.web.context.request.ServletRequestAttributes;
/*     */ 
/*     */ public class ServletUtils {
/*  22 */   private static final String[] agent = new String[] { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
/*     */   
/*     */   public static String getParameter(String name) {
/*  29 */     return getRequest().getParameter(name);
/*     */   }
/*     */   
/*     */   public static String getParameter(String name, String defaultValue) {
/*  37 */     return Convert.toStr(getRequest().getParameter(name), defaultValue);
/*     */   }
/*     */   
/*     */   public static Integer getParameterToInt(String name) {
/*  45 */     return Convert.toInt(getRequest().getParameter(name));
/*     */   }
/*     */   
/*     */   public static Integer getParameterToInt(String name, Integer defaultValue) {
/*  53 */     return Convert.toInt(getRequest().getParameter(name), defaultValue);
/*     */   }
/*     */   
/*     */   public static HttpServletRequest getRequest() {
/*  61 */     return getRequestAttributes().getRequest();
/*     */   }
/*     */   
/*     */   public static HttpServletResponse getResponse() {
/*  69 */     return getRequestAttributes().getResponse();
/*     */   }
/*     */   
/*     */   public static HttpSession getSession() {
/*  77 */     return getRequest().getSession();
/*     */   }
/*     */   
/*     */   public static ServletRequestAttributes getRequestAttributes() {
/*  82 */     RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
/*  83 */     return (ServletRequestAttributes)attributes;
/*     */   }
/*     */   
/*     */   public static String renderString(HttpServletResponse response, String string) {
/*     */     try {
/*  97 */       response.setContentType("application/json");
/*  98 */       response.setCharacterEncoding("utf-8");
/*  99 */       response.getWriter().print(string);
/* 101 */     } catch (IOException e) {
/* 103 */       e.printStackTrace();
/*     */     } 
/* 105 */     return null;
/*     */   }
/*     */   
/*     */   public static boolean isAjaxRequest(HttpServletRequest request) {
/* 115 */     String accept = request.getHeader("accept");
/* 116 */     if (accept != null && accept.indexOf("application/json") != -1)
/* 118 */       return true; 
/* 121 */     String xRequestedWith = request.getHeader("X-Requested-With");
/* 122 */     if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
/* 124 */       return true; 
/* 127 */     String uri = request.getRequestURI();
/* 128 */     if (MyStringUtils.inStringIgnoreCase(uri, new String[] { ".json", ".xml" }))
/* 130 */       return true; 
/* 133 */     String ajax = request.getParameter("__ajax");
/* 134 */     if (MyStringUtils.inStringIgnoreCase(ajax, new String[] { "json", "xml" }))
/* 136 */       return true; 
/* 138 */     return false;
/*     */   }
/*     */   
/*     */   public static boolean checkAgentIsMobile(String ua) {
/* 146 */     boolean flag = false;
/* 147 */     if (!ua.contains("Windows NT") || (ua.contains("Windows NT") && ua.contains("compatible; MSIE 9.0;")))
/* 150 */       if (!ua.contains("Windows NT") && !ua.contains("Macintosh"))
/* 152 */         for (String item : agent) {
/* 154 */           if (ua.contains(item)) {
/* 156 */             flag = true;
/*     */             break;
/*     */           } 
/*     */         }   
/* 162 */     return flag;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\ServletUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */